import {
	defineStore
} from 'pinia'
import {
	fetchAllLabelsApi,
	fetchOtherPlayApi,
	fetchPlayByLableApi
} from '../../service/api'
import {
	iscode
} from '../../utils/iscode'
import useCommonStore from '../common/common'


const useTheaterStore = defineStore('theater', {
	state: () => ({
		tabs: [],
		theaterData: {
			total: 0,
			list: []
		},
		theaterOtherData: []
	}),
	actions: {
		// 获取所有标签
		async fetchAllLabels() {
			const res = await fetchAllLabelsApi()
			if (iscode(res)) {
				const {
					list
				} = res.result

				this.tabs = list
			}
		},
		// 根据标签获取对应数据
		async fetchTheaterDataAction(label_id, pagData) {
			const res = await fetchPlayByLableApi(label_id, pagData)
			if (iscode(res)) {
				const {
					count,
					list
				} = res.result

				this.theaterData.total = count
				this.theaterData.list = list
			}
		},
		// 获取第一个标签里的精选数据
		async fetchTheaterOtherDataAction() {
			const res = await fetchOtherPlayApi()
			if (iscode(res)) {
				const {
					list
				} = res.result

				this.theaterOtherData = list
			}
		}
	}
})

export default useTheaterStore